﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PingPongMain
{
    public class TomCatPingPongMain
    {
        public static Random rand = new Random();

        static void Main(string[] args)
        {

            Ball theBall = new Ball(new Coords(PrepareField.WorldRows / 2, PrepareField.WorldCols / 2), true, false);
            Paddle firstPlayerPaddle = new Paddle();
            firstPlayerPaddle = new Paddle(new Coords((PrepareField.WorldRows / 2) - 3, 0));
            Paddle secondPaddle = new Paddle(new Coords((PrepareField.WorldRows / 2 - 3), PrepareField.WorldCols - 2));
            int difficulty = PrepareField.StartingScreen();
            Bonus bonus = new Bonus(new Coords(rand.Next(1, PrepareField.WorldRows - 3), rand.Next(PrepareField.WorldCols / 2, PrepareField.WorldCols - 1)));
            
            IEventHandler keybord = new Keybord();
            keybord.OnUpArrowPressed += (sender, eventInfo) =>
            {
                firstPlayerPaddle.MoveUp();
            };
            keybord.OnDownArrowPressed += (sender, eventInfo) =>
            {
                firstPlayerPaddle.MoveDown();
            };
            keybord.OnPausePressed += (sender, eventInfo) =>
            {

                Console.SetCursorPosition(PrepareField.WorldCols / 2 - 10, PrepareField.WorldRows / 2);
                Console.Write("Pause! Press any key to continue");
                Console.ReadKey();

            };

            while (true)
            {
                keybord.Processes();
                Console.Clear();
                Score.DisplayScore();
                PrepareField.SetGameField();

                AIMovement.MoveBonus(bonus);
                bonus.Draw();
                bonus = PaddleCollision.BonusCollision(bonus, firstPlayerPaddle);

                firstPlayerPaddle.Draw();
                secondPaddle.Draw();
                theBall.Draw();

                AIMovement.MoveBall(theBall);
                AIMovement.MoveAIPaddle(secondPaddle, theBall, difficulty);

                PaddleCollision.BallCollision(theBall, firstPlayerPaddle, secondPaddle);
                System.Threading.Thread.Sleep(100);
            }
        }
    }
}
